<template>
    <div>
        <h1>编辑</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>DMname</td>
                    <td><input type="text" v-model="data.DMname"></td>
                </tr>
                <tr>
                    <td>DMnum</td>
                    <td><input type="number" v-model="data.DMnum"></td>
                </tr>
                <tr>
                    <td>DMms</td>
                    <td><textarea placeholder="科室描述" v-model="data.DMms"></textarea></td>
                </tr>
                <tr>
                    <td>DMtimes</td>
                    <td><input type="date" v-model="data.DMtimes"></td>
                </tr>
                <tr>
                    
                    <td><input type="button" value="修改" class="btn btn-success" @click="tianj()"></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';
const route = useRoute();

onMounted(() => {
    FTian();
});
const data = ref({
  "DMid": 0,
  "DMname": "",
  "DMnum": null,
  "DMms": "",
  "DMtimes": "",
  "IsDel": 1
})
const FTian = ()=>{
    var mid = route.query.id
    axios.get("https://localhost:7292/api/Deparment/FTKS",{params:{id:mid}}).then(res=>{
        data.value=res.data
        data.value.DMtimes = moment(data.value.DMtimes).format("YYYY-MM-DD");
    })
}
const tianj = ()=>{
    axios.post("https://localhost:7292/api/Deparment/UptKS",data.value).then(res=>{
        if(res.data==-1)
        {
            alert("名称不能重复!!");
        }
        else if(res.data==1)
        {
            alert("修改成功");
            location.href="/";
        }
        else
        {
            alert("修改失败");
        }
    })
}
</script>

<style scoped>

</style>